package com.naiyumi.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.naiyumi.common.DB;
import com.naiyumi.common.DBConnect;
import com.naiyumi.dao.LoginDao;
import com.naiyumi.model.UserInfo;

@Repository
public class LoginDaoImpl implements LoginDao{
	
	@Autowired
	protected DB dbUtil;
	@Autowired
	private DBConnect dbConnect;
	
	public UserInfo checkLogin(String loginName,String loginPassword){
		StringBuffer sql = new StringBuffer();
		sql.append("select * from g_user_info where login_name = '").append(loginName).append("' ").append(" and login_password= '").append(loginPassword).append("'");
//		ResultSet rs = dbUtil.querySql(sql.toString());
//		try {
//			rs.moveToCurrentRow();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		List<Map> mapper = dbConnect.execQuery(sql.toString());
		UserInfo userinfo = new UserInfo();
		if(mapper.size()==1){
			userinfo.setUserId(mapper.get(0).get("USER_ID") == null ? "" : mapper.get(0).get("USER_ID").toString());
			userinfo.setUserName(mapper.get(0).get("USER_NAME") == null ? "" : mapper.get(0).get("USER_NAME").toString());
			userinfo.setLoginName(mapper.get(0).get("LOGIN_NAME") == null ? "" : mapper.get(0).get("LOGIN_NAME").toString());
			userinfo.setLoginPassword(mapper.get(0).get("LOGIN_PASSWORD") == null ? "" : mapper.get(0).get("LOGIN_PASSWORD").toString());
			userinfo.setCreateTime(mapper.get(0).get("CREATE_TIME") == null ? "" : mapper.get(0).get("CREATE_TIME").toString());
			userinfo.setAddress(mapper.get(0).get("ADDRESS") == null ? "" : mapper.get(0).get("ADDRESS").toString());
			userinfo.setTelphone(mapper.get(0).get("TELPHONE") == null ? "" : mapper.get(0).get("TELPHONE").toString());
			userinfo.setEmail(mapper.get(0).get("EMAIL") == null ? "" : mapper.get(0).get("EMAIL").toString());
			userinfo.setMobilephone(mapper.get(0).get("MOBILEPHONE") == null ? "" : mapper.get(0).get("MOBILEPHONE").toString());
			userinfo.setAdmin(mapper.get(0).get("admin") == null ? null : "1".equals(mapper.get(0).get("admin").toString()) ? true : false);
			userinfo.setRemark(mapper.get(0).get("") == null ? "" : mapper.get(0).get("").toString());
		} else {
			userinfo = null;
		}
		return userinfo;
	}
}
